<template>
	<el-dialog :title="dialogTitle" :visible.sync="visible" top="0" width="560px" append-to-body>
		<el-form v-bind="formConfig" :model="formData" :rules="formRules" label-width="80px" v-loading="loading">
			<el-row :gutter="16">
				<el-col :span="24">
					<el-form-item label="广告名称" prop="name">
						<el-input v-model="formData.name" placeholder="请输入广告名称"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="广告图片" prop="fileId">
						<sw-image-uploader v-model="formData.fileId" clip ratio="16:5" size="430" @change="handleUploadChange" />
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="广告链接" prop="linkAddr">
						<el-input v-model="formData.linkAddr" placeholder="请输入广告链接"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="是否显示" prop="isShow">
						<el-radio-group v-model="formData.isShow" v-removeAriaHidden:radio>
							<el-radio label="0">显示</el-radio>
							<el-radio label="1">隐藏</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="排序" prop="orderBy">
						<el-input-number v-model="formData.orderBy" controls-position="right" :min="1" style="width: 100%"></el-input-number>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="广告描述">
						<el-input type="textarea" v-model="formData.des"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template slot="footer">
			<el-button size="medium" @click="visible = false">取消</el-button>
			<el-button size="medium" type="primary" :loading="btnLoading" @click="handleSubmitForm()">{{ formTypeName }}</el-button>
		</template>
	</el-dialog>
</template>

<script>
import formMixins from '@/mixins/formMixins';
import { picSourceDetail, addedPicSource, updatePicSource } from '@/api/website/sysPicSource';
export default {
	props: {
		columnId: { type: String, default: '' }
	},
	mixins: [formMixins],
	data() {
		return {
			formName: '广告',
			formRules: {
				name: [{ required: true, message: '请输入广告名称', trigger: 'blur' }],
				linkAddr: [{ required: true, message: '请输入广告链接', trigger: 'blur' }],
				fileId: [{ required: true, message: '请上传广告图片', trigger: 'change' }],
				isShow: [{ required: true, message: '请选择是否显示', trigger: 'change' }]
			}
		};
	},
	computed: {
		detailData() {
			return eval(picSourceDetail);
		},
		callFunction() {
			return eval(this.addOrEdit ? addedPicSource : updatePicSource);
		},
		submitParams() {
			let datas = { ...this.formData };
			datas['columnId'] = this.columnId;
			return { ...datas, status: '1' };
		}
	},
	methods: {
		handleUploadChange(data) {
			this.$set(this.formData, 'picAddr', data.attrAddr);
			this.$set(this.formData, 'httpUrl', data.httpUrl);
		}
	}
};
</script>
